//
//  TimData.swift
//  TimMusic
//
//  Created by nkl on 2024/10/25.
//

import Foundation

class TimData {
    static func codeModel(from model: Codable) -> Data? {
        do {
            let encoder = JSONEncoder()
            let data = try encoder.encode(model)
            // 现在 data 是一个 Data 类型，表示编码后的 MyWidgetsModel
            return data
        } catch {
            return nil
        }
    }

    static func decodeModel<T: Codable>(from data: Data) -> T? {
        do {
            let decoder = JSONDecoder()
            let decodedModel = try decoder.decode(T.self, from: data)
            return decodedModel
        } catch {
            print("Failed to decode MyWidgetsModel: \(error)")
            return nil
        }
    }
}

